package com.iisageek.client.widgets.xml;

import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;
import com.google.gwt.user.client.Window;

public class Server {
	
	public static boolean requestData(String path, XMLHandler handler){
		return HTTPRequest.asyncGet(path,new ServerHandler(handler));
	}

	public static boolean requestData(String path, String postData, XMLHandler handler){
		return HTTPRequest.asyncPost(path, postData, new ServerHandler(handler));
	}
	
	public static boolean sendData(String path, String postData, XMLHandler handler) {
		return HTTPRequest.asyncPost(path, postData, new ServerHandler(handler));
	}
	
	private static class ServerHandler implements ResponseTextHandler {
		
		XMLHandler handler;
		
		public ServerHandler(XMLHandler handler){
			this.handler = handler;
		}
		
		public void onCompletion(String response){
			Node element = Node.parseXML(response);
			handler.receivedData(element);
		}
			
	}
	
}
